[XM] new.py that implements adding an unstarted domain
authoracnt2@huggins.lce.cl.cam.ac.uk <acnt2@huggins.lce.cl.cam.ac.uk>
Thu, 5 Oct 2006 16:29:19 +0000 (17:29 +0100)
committeracnt2@huggins.lce.cl.cam.ac.uk <acnt2@huggins.lce.cl.cam.ac.uk>
Thu, 5 Oct 2006 16:29:19 +0000 (17:29 +0100)
Signed-off-by: Alastair Tse <atse@xensource.com>
tools/python/xen/xm/new.py [new file with mode: 0644]

diff --git a/tools/python/xen/xm/new.py b/tools/python/xen/xm/new.py
new file mode 100644 (file)
index 0000000..fec2fc7
--- /dev/null
@@ -0,0 +1,68 @@
+#============================================================================
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of version 2.1 of the GNU Lesser General Public
+# License as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#============================================================================
+# Copyright (C) 2006 XenSource Ltd
+#============================================================================
+
+import os
+import xmlrpclib
+
+from xen.xend import PrettyPrint
+from xen.xend import sxp
+from xen.xend import XendClient
+from xen.xend.XendClient import server
+
+from xen.xm.opts import *
+from xen.xm.create import *
+
+def make_unstarted_domain(opts, config):
+    """Create an unstarted domain.
+
+    @param opts:   options
+    @param config: configuration
+    """
+    try:
+        server.xend.domain.new(config)
+    except xmlrpclib.Fault, ex:
+        import signal
+        if vncpid:
+            os.kill(vncpid, signal.SIGKILL)
+        if ex.faultCode == XendClient.ERROR_INVALID_DOMAIN:
+            err("the domain '%s' does not exist." % ex.faultString)
+        else:
+            err("%s" % ex.faultString)
+    except Exception, ex:
+        import signal
+        if vncpid:
+            os.kill(vncpid, signal.SIGKILL)
+        err(str(ex))
+
+
+def main(argv):
+    try:
+        (opts, config) = parseCommandLine(argv)
+    except StandardError, ex:
+        err(str(ex))
+
+    if not opts:
+        return
+
+    if opts.vals.dryrun:
+        PrettyPrint.prettyprint(config)
+    else:
+        make_unstarted_domain(opts, config)
+        
+if __name__ == '__main__':
+    main(sys.argv)
+